<template>
	<view>
		<view class="Search">
			<template>
				<u-search placeholder="请输入搜索内容" height="40" :clearabled="true" :showAction="false"
					v-model="params.title" @clear='onsearch()' @search='onsearch()'></u-search>
			</template>
		</view>
		<view @click="onclick(item.id)" v-for="(item,index) in list" :key="index">
			<view class="box">
				<view class="title">
					{{item.title}}
				</view>
				<view class="tag" v-if="item.tags">
					<view class="tag-y" v-for="(nav,j) in item.tags.split(',')" :key="j">
						{{nav}}
					</view>
				</view>
				<view class="card">
					<view class="left">
						<img src="https://img.wilmer.com.cn/admin/2024/Group%20265.png" alt="" />
					</view>
					<view class="right">{{item.title}}</view>
				</view>
			</view>
			<view class="hr"></view>
		</view>
		<image v-if="list.length == 0" class="NoData" src="https://img.wilmer.com.cn/admin/2024/3-20/WechatIMG19.jpg"
			mode=""></image>
		<view style="height: 100rpx;width: 1rpx;"></view>
	</view>
</template>

<script>
	import {
		Getdocument
	} from '@/common/api/homePage.js'
	export default {
		data() {
			return {
				list: [],
				total: 0,
				params: {
					pageNum: 1,
					pageSize: 10,
					title: ""
				},
				flag: true, // 上拉加载开关 防止一次触底查询多次问题,防止数据查完后触底还调接口问题
				status: 'loadmore', // loading || loadmore
				loadingText: '努力加载中',
				loadmoreText: '轻轻上拉,加载更多数据',
				nomoreText: '实在没有了',

			}
		},
		onLoad() {
			this.GetList()
		},
		onReachBottom() {
			let that = this
			if (that.total > that.list.length) {
				that.status = 'loading'
				if (!this.flag) {
					that.GetList()
					uni.stopPullDownRefresh()
				}
			} else {
				this.status = 'nomore'
			}
		},
		methods: {
			onclick(id) {
				uni.navigateTo({
					url: `/pages/school/Document-details?id=${id}`
				})
			},
			GetList() {
				uni.showLoading({
					title: '加载中'
				});
				Getdocument(this.params).then(res => {
					setTimeout(() => {
						uni.hideLoading();
					}, 500)
					this.list = res.data.rows
					this.total = res.data.total

					if (res.data.total < 10) {
						this.status = 'nomore'
						this.flag = true
					} else {
						this.status = 'loadmore'
						this.flag = false
						this.params.pageSize = this.params.pageSize + 10
					}
				})
			},
			onsearch() {
				this.GetList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.Search {
		margin-top: 4rpx;
		padding: 0 32rpx;
	}

	.box {
		padding: 20rpx 32rpx;
		margin-top: 32rpx;

		.title {
			font-size: 28rpx;
			font-weight: 500;
			margin-bottom: 20rpx;
			color: #333333;
		}

		.tag {
			display: flex;
			margin-bottom: 30rpx;

			.tag-y {
				font-size: 14px;
				font-weight: 400;
				color: #E0A134;
				background-color: #FFF9E4;
				border-radius: 12rpx;
				padding: 12rpx 14rpx;
				margin-right: 20rpx;
			}
		}

		.card {
			background-color: #f8f8f8;
			border-radius: 14rpx;
			padding: 32rpx;
			display: flex;

			.left {
				img {
					width: 48rpx;
					height: 52rpx;
				}
			}

			.right {
				font-size: 14px;
				font-weight: 400;
				margin-left: 14rpx;
				color: #666666;
			}
		}
	}

	.hr {
		width: 100vw;
		height: 8rpx;
		background-color: #f8f8f8;
		margin-top: 30rpx;
	}

	.NoData {
		display: block;
		width: 400rpx;
		height: 318rpx;
		margin: 40rpx auto 0;
	}
</style>